<?php
/**
 *微店铺
 *@author 
 *@QQ 457178642
 *@2013-11-24
 */
class WshopAction extends Action
{
	const PAGE_SIZE = 5;
	public function index()
	{
		$now_page = $this->_get('page');
		if(empty($now_page)){
			$now_page = 1;
		}
		$page_size = self::PAGE_SIZE;
		$res = WshopModel::getShopList(($now_page-1)*$page_size,$page_size,'',array("level"=>"desc"));
		$count = WshopModel::getShopCount();

		$page = array(
			'count' => $count,
			'page_size' => $page_size,
			'now_page' => $now_page,
			);

		foreach($res as &$shop){
			$options['shop_id'] = $shop['shop_id']; 
			$goods = GoodsModel::getGoodsList(0, 6, $options, array("view_count" => 'desc'));
			$shop['goods_list'] = $goods;
		}

		//ad
		$options['place_tag'] = 'wshop1';
		$options1['place_tag'] = 'wshop2';
		$this->lunbo_ad = AdModel::getAdList($options);
		$this->right_ad = AdModel::getAdList($options1);

		$this->assign("page",$page);
		$this->assign("shoplist",$res);
		$this->assign("current_class",2);

		$this->goods_view=unserialize(stripslashes(cookie('goods_view')));
		$this->cat=R('Goods/goods_cat');
		$shop_cart=cookie('shopcart');
		$this->cart_num=!empty($shop_cart)?count(unserialize(stripslashes($shop_cart))):0;
		$this->assign("cat_now", $cat_now);
		$this->name= "品牌街-蚂蚁街";
		$this->user=$_SESSION['euname'];
		$this->assign("keyword",$key);
		$this->display();
	}

	public function home()
	{
		$domain = $this->_get('domain');
		$id = $this->_get("id");
		if(!empty($domain)){
			$map['domain'] = $domain;
		}else if(!empty($id)){
			$map['shop_id'] = $id;
		}else{
			header("Location: /");
		}
		$shop = WshopModel::getShopDetail($map);
		if(empty($shop)){
			header("Location: /");
		}

		$now_page = $this->_get('page');
		if(empty($now_page)){
			$now_page = 1;
		}
		$page_size = 20;

		$options['shop_id'] = $shop['shop_id']; 
		$goods = GoodsModel::getGoodsList(($now_page-1)*$page_size,$page_size, $options, array("view_count" => 'desc'));
		$count = GoodsModel::getCount($options);

		$page = array(
			'count' => $count,
			'page_size' => $page_size,
			'now_page' => $now_page,
			);
        
		$this->assign("goods",$goods);
		$this->assign("shop",$shop);
		$this->assign("page",$page);

		$this->goods_view=unserialize(stripslashes(cookie('goods_view')));
		$this->cat=R('Goods/goods_cat');
		$shop_cart=cookie('shopcart');
		$this->cart_num=!empty($shop_cart)?count(unserialize(stripslashes($shop_cart))):0;
		$this->assign("cat_now", $cat_now);
		$this->name= $shop['shop_name']."-蚂蚁街";
		$this->user=$_SESSION['euname'];
		$this->assign("keyword",$key);
		$this->display();
	}
}